#include <iostream>
#include <bitset>
#include <math.h>
using namespace std;
/**
 * @brief
 * 0 <= num <= 10^6
 *
 */
class Solution
{
public:
    int numberOfSteps(int num)
    {
        int count = 0;
        while (num)
        {
            if (num % 2 == 0)
            {
                num >>= 1;
            }
            else
            {
                num -= 1;
            }
            count++;
        }
        return count;
    }

    int numberOfSteps_2(int n)
    {
        return n ? log2(n) + bitset<32>(n).count() : 0;
    }
};
int main()
{
    Solution s;
    cout << s.numberOfSteps_2(123) << endl;
    return 0;
}
